package com.eclink.asset.workflow.domain.dao;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.eclink.asset.domain.dao.CommonEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
public class FlowTask extends CommonEntity {

    private static final long serialVersionUID = -342059015969002827L;

    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty("ID")
    private String id;

    // 名称
    private String name;

    // 参与审批的用户
    @TableField(exist = false)
    private List<FlowTaskAuditUser> auditUser;

    // 任务的审批记录
    @TableField(exist = false)
    private List<FlowTaskApprove> approveList;

    // 审批规则
    private Integer auditRule;

    // 任务类型
    private Integer taskType;

    // 审批内容
    private String content;

    // 状态
    private int state;

    // 申请的时间
    private LocalDateTime applyTime;

    // 开始时间
    private LocalDateTime startTime;

    // 结束时间
    private LocalDateTime endTime;

    // 申请的ID
    private String applyId;

    // 申请类型
    private String applyType;

    // 申请编号
    private String applyNumber;

    // 待办的类型 1-审批 2-用户申请 3-调拨单
    private Integer todoType;

    // 工作流ID
    private String flowId;

    // 下一个任务的ID
    private String nextTaskId;

    /**
     * 检查用户是否可以审批
     * @param userId ID
     *
     * @return 结果
     */
    public FlowTaskAuditUser findAuditUser(Long userId) {
        return auditUser.stream().filter(item->item.getUserId().equals(userId)).findFirst().orElse(null);
    }

}
